package com.hsd.service.Impl;

import com.hsd.entity.Category;
import com.hsd.mapper.ICategoryMapper;
import com.hsd.service.ICategoryService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
@Service
public class ICategoryServiceImpl implements ICategoryService {
    @Resource
    private ICategoryMapper iCategoryMapper;

    /**
     * 显示所有的父分类
     * @return
     */
    @Transactional(readOnly = true)
    public List<Category> findAll() {
        return iCategoryMapper.selectAllFu();
    }

    /**
     * 通过父分类显示子分类
     * @param parent
     * @return
     */
    @Transactional(readOnly = true)
    public List<Category> findByPToCh(Integer parent) {
        return iCategoryMapper.selectByPTCh(parent);
    }

    /**
     * 添加分类信息
     * @param category
     * @return
     */
    @Transactional(isolation = Isolation.READ_COMMITTED,propagation = Propagation.REQUIRED)
    public boolean addCategory(Category category) {
        return iCategoryMapper.addCategory(category)>0;
    }

    /**
     * 通过编号删除分类信息
     * @param id
     * @return
     */
    @Transactional(isolation = Isolation.READ_COMMITTED,propagation = Propagation.REQUIRED)
    public boolean deleteCategory(Integer id) {
        return iCategoryMapper.deleteCategory(id)>0;
    }

    /**
     * 通过编号修改分类信息
     * @param category
     * @return
     */
    @Transactional(isolation = Isolation.READ_COMMITTED,propagation = Propagation.REQUIRED)
    public boolean updateCategory(Category category) {
        return iCategoryMapper.updateCategory(category)>0;
    }
}
